package UI.BaseModels;

import java.awt.Color;

import javax.swing.JPanel;

import threads.BaseRunnableBCBS;
import java.awt.Canvas;

/**
 * All our Panels inherit from this object, as this has all the common options
 * of our panels, such as a back-button, a feedback label and the ability to
 * hold the current thread for the panel as an object and the ability to stop it.
 * 
 */
public class BCBSPanel extends JPanel {

	protected FeedbackLabel feedbackLabel;
	protected BaseRunnableBCBS runnable;
	protected Color feedbackGreen = new Color(51, 151, 0);
	protected Color feedbackRed = new Color(255, 0, 0);

	/**
	 * 
	 */
	private static final long serialVersionUID = -3480171839351181268L;

	public BCBSPanel() {
		setBounds(0, 0, 312, 446);
		setLayout(null);
		feedbackLabel = new FeedbackLabel();

		this.add(feedbackLabel);
	}

	/**
	 * Clears the feedback-label for the current panel.
	 */
	public void clearFeedback() {
		feedbackLabel.setText("");

	}

	/**
	 * Supplies feedback to the user for the current panel in appropriate color.
	 * 
	 * @param feedback
	 *            The text string to display to the user.
	 * @param value
	 *            If true the text is green, if false the text is red.
	 */
	public void feedback(String feedback, boolean value) {
		if (value) {
			feedbackLabel.setText(feedback);
			feedbackLabel.setForeground(feedbackGreen);
		} else {
			feedbackLabel.setText(feedback);
			feedbackLabel.setForeground(feedbackRed);
		}

	}

	/**
	 * Resets all fields for the panel. Must be overridden by panels to
	 * customize.
	 */
	public void clearFields() {
		// empty - must always be overridden.
	}

	/**
	 * Stops the currently running thread for the current panel, if any.
	 */
	public void stopThread() {
		if (runnable != null) {
			runnable.stop();
		}
	}
}
